package com.oocl.homework0712.multithreaddownload.thread;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import com.oocl.homework0712.multithreaddownload.Start;

public class ThreadIn implements Runnable{
	private File file1;

	private int id;
	private byte[] buf;

	public ThreadIn(File file1,  int id,byte[] buf) {
		super();
		this.file1 = file1;

		this.id = id;
		this.buf = buf;
	}
	public void run() {
		// TODO Auto-generated method stub
		InputStream in;
		String dString;
		try {
			synchronized (file1) {
				if(buf[0]==0){
				in = new FileInputStream(file1);
				in.skip(id*buf.length);
				in.read(buf);
				//buf.notify();
				Start.sleep(1000);
				dString = new String(buf);
				System.out.println(dString);
				in.close();
				}
				else {
					//buf.wait();
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

}
